<?php
namespace Api\Controller;
use Think\Controller;
class IndexController extends BaseController {


    /**
     *    小程序首页获取信息
     */
    public function index()
    {

        $work = M('works')->distinct(true)->where("is_show = 1")->field('id,name,image,b_id')->group('b_id')->select();


        C('SHOW_PAGE_TRACE','');
        //获取所有的轮播图
        $sowing = M('sowing')->where("is_delete = 0 and is_show = 1")->select();

        //获取所有的目的地
        $de_list = M('destination')->where('is_recommend = 1')->field('id,name,imaged')->order('sort desc')->limit(5)->select();

        //获取首页6个页面的数据图片
        $de_show = M('destination')->field('name,id,image')->where('is_show = 1')->order('sort desc')->limit(4)->select();

        //获取视频和内容的功能
        $video = M('config')->where('name="video"')->select();

        //获取电话号码
        $phone = M('config')->where('name = "phone"')->select();

        //获取客片（每周全国各地轮播4组）
        $photo = M('works')->where('is_show = 1 ')->field('id,image')->limit(4)->select();

        //获取所有的公司简介
        $company_list = M('infor')->field('id,name,image')->select();

        //获取首页客户评价
        $evaluate  = M('evaluate')->field('id,name,content,create_at,image')->limit(6)->select();



        //获取样片系统
        $sample = M('sample')->field('id,name,image')->limit(4)->select();
        foreach ($evaluate as &$a){
            $a['time'] =  date('Y-m-d', time($a['create_at']));
        }


        $work = M('works')->select();
        echo json_encode(
            array(
                'sowing' => $sowing,
                'de_list'=>$de_list,
                'de_show'=>$de_show,
                'video'=>$video,
                'phone'=>$phone,
                'photo' =>$photo,
                'company_list' =>$company_list,
                'evaluate' =>$evaluate,
                'sample'=>$sample,
                'work' =>$work,
            )
        );

    }

}
